package cl.fbd.widget_examples.web.snippet

import scala.xml.{NodeSeq, Node, PCData, Text, Unparsed}

import net.liftweb.widgets.trees.model._
import net.liftweb.widgets.trees.treetable._
import cl.fbd.widget_examples.web.model.{TimeSerieMeasureModel, TimeSerie, Measure}

import net.liftweb.util.Helpers._



/*
 * render a treetable of measure and time series
 */

class TreeTableAlone {
  
  def renderMeasure (xhtml: NodeSeq, measure : Measure) = {
    bind ("measure", xhtml, "mm" --> measure.value, 
                             "date" --> Constants.sdf.format (measure.when))
  }
  
  def renderTimeSerie (xhtml: NodeSeq, timeserie : TimeSerie) = {
    bind ("timeserie", xhtml, "name" --> (timeserie.what + " / " + timeserie.where),  
                             "sum" --> timeserie.sum)
  }
  
  def render (xhtml: NodeSeq) = {
    val model = TimeSerieMeasureModel.initModel  
    
    bind ("treetable", xhtml, "render" --> 
      net.liftweb.widgets.trees.treetable.TreeTable.render (
        model, 
        new net.liftweb.widgets.trees.treetable.TreeTableOptions,
        renderMeasure, renderTimeSerie
        ))
  }
}

